package androidx.preference;

import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.j;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.f;
import b.f.l.s;
import java.util.ArrayList;
import java.util.List;

public class h extends RecyclerView.g<l> implements Preference.c, PreferenceGroup.c {

    /* renamed from: c  reason: collision with root package name */
    private PreferenceGroup f812c;

    /* renamed from: d  reason: collision with root package name */
    private List<Preference> f813d;
    private List<Preference> e;
    private List<d> f;
    private Handler g;
    private Runnable h = new a();

    class a implements Runnable {
        a() {
        }

        public void run() {
            h.this.K();
        }
    }

    class b extends f.b {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ List f815a;

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ List f816b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ j.d f817c;

        b(h hVar, List list, List list2, j.d dVar) {
            this.f815a = list;
            this.f816b = list2;
            this.f817c = dVar;
        }

        public boolean a(int i, int i2) {
            return this.f817c.a((Preference) this.f815a.get(i), (Preference) this.f816b.get(i2));
        }

        public boolean b(int i, int i2) {
            return this.f817c.b((Preference) this.f815a.get(i), (Preference) this.f816b.get(i2));
        }

        public int d() {
            return this.f816b.size();
        }

        public int e() {
            return this.f815a.size();
        }
    }

    class c implements Preference.e {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ PreferenceGroup f818a;

        c(PreferenceGroup preferenceGroup) {
            this.f818a = preferenceGroup;
        }

        public boolean onPreferenceClick(Preference preference) {
            this.f818a.Q0(Integer.MAX_VALUE);
            h.this.a(preference);
            PreferenceGroup.b J0 = this.f818a.J0();
            if (J0 == null) {
                return true;
            }
            J0.a();
            return true;
        }
    }

    private static class d {

        /* renamed from: a  reason: collision with root package name */
        int f820a;

        /* renamed from: b  reason: collision with root package name */
        int f821b;

        /* renamed from: c  reason: collision with root package name */
        String f822c;

        d(Preference preference) {
            this.f822c = preference.getClass().getName();
            this.f820a = preference.p();
            this.f821b = preference.C();
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof d)) {
                return false;
            }
            d dVar = (d) obj;
            return this.f820a == dVar.f820a && this.f821b == dVar.f821b && TextUtils.equals(this.f822c, dVar.f822c);
        }

        public int hashCode() {
            return ((((527 + this.f820a) * 31) + this.f821b) * 31) + this.f822c.hashCode();
        }
    }

    public h(PreferenceGroup preferenceGroup) {
        this.f812c = preferenceGroup;
        this.g = new Handler();
        this.f812c.r0(this);
        this.f813d = new ArrayList();
        this.e = new ArrayList();
        this.f = new ArrayList();
        PreferenceGroup preferenceGroup2 = this.f812c;
        B(preferenceGroup2 instanceof PreferenceScreen ? ((PreferenceScreen) preferenceGroup2).T0() : true);
        K();
    }

    private b D(PreferenceGroup preferenceGroup, List<Preference> list) {
        b bVar = new b(preferenceGroup.i(), list, preferenceGroup.m());
        bVar.s0(new c(preferenceGroup));
        return bVar;
    }

    private List<Preference> E(PreferenceGroup preferenceGroup) {
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        int L0 = preferenceGroup.L0();
        int i = 0;
        for (int i2 = 0; i2 < L0; i2++) {
            Preference K0 = preferenceGroup.K0(i2);
            if (K0.I()) {
                if (!H(preferenceGroup) || i < preferenceGroup.I0()) {
                    arrayList.add(K0);
                } else {
                    arrayList2.add(K0);
                }
                if (!(K0 instanceof PreferenceGroup)) {
                    i++;
                } else {
                    PreferenceGroup preferenceGroup2 = (PreferenceGroup) K0;
                    if (!preferenceGroup2.M0()) {
                        continue;
                    } else if (!H(preferenceGroup) || !H(preferenceGroup2)) {
                        for (Preference next : E(preferenceGroup2)) {
                            if (!H(preferenceGroup) || i < preferenceGroup.I0()) {
                                arrayList.add(next);
                            } else {
                                arrayList2.add(next);
                            }
                            i++;
                        }
                    } else {
                        throw new IllegalStateException("Nesting an expandable group inside of another expandable group is not supported!");
                    }
                }
            }
        }
        if (H(preferenceGroup) && i > preferenceGroup.I0()) {
            arrayList.add(D(preferenceGroup, arrayList2));
        }
        return arrayList;
    }

    private void F(List<Preference> list, PreferenceGroup preferenceGroup) {
        preferenceGroup.S0();
        int L0 = preferenceGroup.L0();
        for (int i = 0; i < L0; i++) {
            Preference K0 = preferenceGroup.K0(i);
            list.add(K0);
            d dVar = new d(K0);
            if (!this.f.contains(dVar)) {
                this.f.add(dVar);
            }
            if (K0 instanceof PreferenceGroup) {
                PreferenceGroup preferenceGroup2 = (PreferenceGroup) K0;
                if (preferenceGroup2.M0()) {
                    F(list, preferenceGroup2);
                }
            }
            K0.r0(this);
        }
    }

    private boolean H(PreferenceGroup preferenceGroup) {
        return preferenceGroup.I0() != Integer.MAX_VALUE;
    }

    public Preference G(int i) {
        if (i < 0 || i >= g()) {
            return null;
        }
        return this.e.get(i);
    }

    /* renamed from: I */
    public void s(l lVar, int i) {
        G(i).P(lVar);
    }

    /* renamed from: J */
    public l u(ViewGroup viewGroup, int i) {
        d dVar = this.f.get(i);
        LayoutInflater from = LayoutInflater.from(viewGroup.getContext());
        TypedArray obtainStyledAttributes = viewGroup.getContext().obtainStyledAttributes((AttributeSet) null, t.BackgroundStyle);
        Drawable drawable = obtainStyledAttributes.getDrawable(t.BackgroundStyle_android_selectableItemBackground);
        if (drawable == null) {
            drawable = b.a.k.a.a.d(viewGroup.getContext(), 17301602);
        }
        obtainStyledAttributes.recycle();
        View inflate = from.inflate(dVar.f820a, viewGroup, false);
        if (inflate.getBackground() == null) {
            s.h0(inflate, drawable);
        }
        ViewGroup viewGroup2 = (ViewGroup) inflate.findViewById(16908312);
        if (viewGroup2 != null) {
            int i2 = dVar.f821b;
            if (i2 != 0) {
                from.inflate(i2, viewGroup2);
            } else {
                viewGroup2.setVisibility(8);
            }
        }
        return new l(inflate);
    }

    /* access modifiers changed from: package-private */
    public void K() {
        for (Preference r0 : this.f813d) {
            r0.r0((Preference.c) null);
        }
        ArrayList arrayList = new ArrayList(this.f813d.size());
        this.f813d = arrayList;
        F(arrayList, this.f812c);
        List<Preference> list = this.e;
        List<Preference> E = E(this.f812c);
        this.e = E;
        j x = this.f812c.x();
        if (x == null || x.g() == null) {
            l();
        } else {
            f.a(new b(this, list, E, x.g())).e(this);
        }
        for (Preference c2 : this.f813d) {
            c2.c();
        }
    }

    public void a(Preference preference) {
        this.g.removeCallbacks(this.h);
        this.g.post(this.h);
    }

    public void b(Preference preference) {
        int indexOf = this.e.indexOf(preference);
        if (indexOf != -1) {
            m(indexOf, preference);
        }
    }

    public int c(String str) {
        int size = this.e.size();
        for (int i = 0; i < size; i++) {
            if (TextUtils.equals(str, this.e.get(i).o())) {
                return i;
            }
        }
        return -1;
    }

    public int d(Preference preference) {
        int size = this.e.size();
        for (int i = 0; i < size; i++) {
            Preference preference2 = this.e.get(i);
            if (preference2 != null && preference2.equals(preference)) {
                return i;
            }
        }
        return -1;
    }

    public int g() {
        return this.e.size();
    }

    public long h(int i) {
        if (!k()) {
            return -1;
        }
        return G(i).m();
    }

    public int i(int i) {
        d dVar = new d(G(i));
        int indexOf = this.f.indexOf(dVar);
        if (indexOf != -1) {
            return indexOf;
        }
        int size = this.f.size();
        this.f.add(dVar);
        return size;
    }
}
